﻿ 
using Data.Video;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;

namespace Data.Video
{
    public class Htmls
    {
        List<Category> lst2 = new List<Category>();
        List<Category> lst = null;
        public SelectList SelectListCate(int? selected, bool isAll)
        {
            using (VideoEntities db2 = new VideoEntities())
            {
                lst = db2.Category.ToList();
                if (isAll)
                {
                    var cate=new Category();
                    cate.ID=0;
                    cate.Name="Chon Loại Danh mục";
                    lst2.Add(cate); 
                }
                for (int i = 0; i < lst.Count; i++)
                {
                    var item = lst.ElementAt(i);
                    if (item.Parent == 0)
                    {
                        lst2.Add(lst.ElementAt(i));
                        RecursiveMenu(lst.ElementAt(i).ID, 1);
                    }
                }
                SelectList selectList = new SelectList(lst2, "ID", "Name", selected);
               
                return selectList;
            }
        }
        public SelectList SelectListCateType(int? selected, bool isAll)
        {
            
                SelectList selectList = new SelectList(new[] 
                { 
                 new SelectListItem { Text = "Hình ảnh", Value = "1" },
                 new SelectListItem { Text = "15", Value = "2", },
                 new SelectListItem { Text = "25", Value = "25" },
                 new SelectListItem { Text = "50", Value = "50" },
                 new SelectListItem { Text = "100", Value = "100" },
                 new SelectListItem { Text = "1000", Value = "1000" },
                }, "Value", "Text", selected);
                
                return selectList;
           
        }
       
        private void RecursiveMenu(long? parentId, int lever)
        {
            using (VideoEntities db = new VideoEntities())
            {
                List<Category> lst3 = db.Category.Where(en => en.Parent == parentId).ToList();
                foreach (var item in lst3)
                {
                    var a = "";
                    for (int i = 0; i < lever; i++) { a += "___  "; }
                    item.Name = a + item.Name;
                    lst2.Add(item);
                    RecursiveMenu(item.ID, lever + 1);

                }

            }
        } 
    }
}